package com.appcenter.task.controller;

import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import com.appcenter.task.config.RemoteProperties;
import com.appcenter.task.input.LoadUnTaskListPageInput;
import com.appcenter.task.input.SearchUnTaskListInput;
import com.appcenter.task.input.externalapi.ConversionTaskInput;
import com.appcenter.task.input.externalapi.SendTaskInput;
import com.appcenter.task.service.UnTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jztaskcenterservice/untask")
@Api(value="任务中心API",description = "任务中心API")
public class UnTaskCeneterController {
    @Autowired
    UnTaskService unTaskService;
    @ApiOperation(value = "查询待办信息", notes = "查询待办信息",produces = "application/json")
    @PostMapping("/searchuntasklist")
    public ResponseEntity<JsonResult> SearchUnTaskList(@RequestBody SearchUnTaskListInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(unTaskService.SearchUnTaskList(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    @ApiOperation(value = "加载待办信息", notes = "加载待办信息",produces = "application/json")
    @PostMapping("/loaduntasklistpage")
    public ResponseEntity<JsonResult> LoadUnTaskListPage(@RequestBody LoadUnTaskListPageInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(unTaskService.LoadUnTaskListPage(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "待办转已办", notes = "待办转已办",produces = "application/json")
    @PostMapping("/conversiontask")
    public ResponseEntity<JsonResult> ConversionTask(@RequestBody ConversionTaskInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            input.setAlreadyGenre("管理员办结");
            r.setResult(unTaskService.ConversionTask(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "推送待办", notes = "推送待办",produces = "application/json")
    @PostMapping("/sendtask")
    public ResponseEntity<JsonResult> SendTask(@RequestBody SendTaskInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(unTaskService.SendTask(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
